package com.engine.salary.entity.datacollection.bo;

import com.engine.salary.entity.datacollection.po.AttendQuoteFieldPO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 考勤引用数据
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class AttendQuoteDataBO {

    @Override
    public String toString() {
        return "AttendQuoteDataBO{}";
    }

    /**
     * 根据考勤模块来构建考勤数据
     */
    public static void buildAttendDataFromRemote( List<Map<String, String>> list, List<AttendQuoteFieldPO> attendQuoteFields, List<Map<String, Object>> attendQuoteSyncData) {
            if (CollectionUtils.isEmpty(list)) {
                return;
            }
            list.forEach(m-> {
                for (AttendQuoteFieldPO field : attendQuoteFields) {
                    if (StringUtils.isEmpty(field.getCode())) {
                        continue;
                    }
                    String key = field.getCode();
                    //兼容出勤班次的key
                    if(key.startsWith("attendanceSerial_")){
                        key = key.replace("attendanceSerial_", "");
                    }
                    if (m.containsKey(key)) {
                        Map<String, Object> map = new LinkedHashMap<>();
                        map.put("employeeId", m.get("resourceId"));
                        map.put("attendQuoteFieldId", field.getId());
                        map.put("dataValue", m.get(key));
                        attendQuoteSyncData.add(map);
                    }
                }
            });
    }

//    public static DataCollectionEmployee getCurrentUser4Remote() {
//        DataCollectionEmployee se = UserContext.getCurrentUser();
//        if(se != null){
//            DataCollectionEmployee simple = new DataCollectionEmployee();
//            simple.setId(se.getId());
//            simple.setUserId(se.getUserId());
//            simple.setUsername(se.getUsername());
//            simple.setPinyin(se.getPinyin());
//            simple.setImUid(se.getImUid());
//            simple.setImCid(se.getImCid());
//            simple.setTenantKey(se.getTenantKey());
//            simple.setDepartment(se.getDepartment());
//            simple.setAuthorities(null);
//            return simple;
//        }
//        return null;
//    }
}
